package com.zhengke.controller.cggl;

import com.zhengke.common.object.AjaxDone;
import com.zhengke.common.object.Result;
import com.zhengke.pojo.SysDictionaryItem;
import com.zhengke.pojo.TvPurchaseDetails;
import com.zhengke.service.cggl.CGGL030Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * *******************************
 * 项目名称：tvmall-parent
 * 文件名称：CGGL030Controller
 * 类说明：  采购退货
 * 创建时间：2020/1/14 12:11
 *
 * @author 王东科
 * @version 1.0
 * *******************************
 */
@Controller
@RequestMapping("CGGL030")
public class CGGL030Controller {

    @Autowired
    private CGGL030Service service;
    /**
     * 跳转采购退货
     *
     * @return
     */
    @RequestMapping("toCGGL030.do")
    public String query( ){
        return "cggl/cggl030/cggl0301";
    }

    /**
     * 查询采购退货信息
     * @param goodsName
     * @param page
     * @param limit
     * @return
     */
    @ResponseBody
    @RequestMapping("queryList.do")
    public Result queryList(String goodsName,int page, int limit){
        Result rs = null;
        try {
            rs = service.queryList(goodsName,page,limit);
            return rs;
        } catch (Exception e) {
            e.printStackTrace();
        }

        return new Result();
    }
    /**
     * 跳转到采购商品退货
     *
     * @return
     */
    @RequestMapping("add.do")
    public String add(ModelMap model,HttpServletRequest request){
        String purchaseId=request.getParameter("purchaseId");
        try {
            List<SysDictionaryItem>  list = service.queryListById(0006);
            model.put("list",list);
            model.put("purchaseId",purchaseId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "cggl/cggl030/cggl0302";
    }

    /**
     * 采购商品退货
     * @param request
     * @return
     */
    @ResponseBody
    @RequestMapping("update.do")
    public AjaxDone updateById(HttpServletRequest request){
        String purchaseId=request.getParameter("purchaseId");
        String statu=request.getParameter("statu");
        String ruturnType=request.getParameter("ruturnType");

        TvPurchaseDetails tvPurchaseDetails = new TvPurchaseDetails();
        tvPurchaseDetails.setPurchaseId(purchaseId);
        if (statu != null && statu != "")
        tvPurchaseDetails.setStatu(Short.parseShort(statu));
        tvPurchaseDetails.setRuturnType(ruturnType);
        try {
            if(tvPurchaseDetails.getStatu() !=null && tvPurchaseDetails.getRuturnType() != null) {
                service.updateGoodsDetail(tvPurchaseDetails);
                return new AjaxDone("200", "修改成功");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return new AjaxDone("300","修改失败");
    }

}
